﻿using System;
using System.Windows.Forms;

using ExtensibleEventViewer.Console.Forms;

using log4net;


namespace ExtensibleEventViewer.Console
{
	static class Program
	{
		private readonly static ILog _log = LogManager.GetLogger(typeof(Program));

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			Application.ThreadException += Application_ThreadException;
			AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new MainWnd());
		}

		static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			_log.Error("DomainUnhandledException", (Exception) e.ExceptionObject);
			
			MessageBox.Show(((Exception)e.ExceptionObject).Message);
		}

		static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
		{
			_log.Error("ThreadUnhandledException", e.Exception);
			
			MessageBox.Show(e.Exception.Message);
		}
	}
}
